﻿using System;

namespace PlusPlusPaint.FileIO.AST
{
    class TopLevelNode : INode
    {
        #region member variables
        INode child = null;
        #endregion

        #region overrides
        public override string ToString()
        {
            return "<<<" + child + ">>>\r\n";
        }
        #endregion

        #region public methods
        public string ToPrettyString()
        {
            return "<<<\r\n" + INodeHelpers.Indent(child.ToPrettyString(), INodeHelpers.PrettyStringIndent) + "\r\n>>>\r\n";
        }

        public SerializedObject ToSerializedObject()
        {
            if (child == null)
                throw new Exception("Internal Parser Error:  Ungrammatical empty top level so.");
            return child.ToSerializedObject().CloneWithName("TopLevelNode");
        }

        public void AddArg(string name, int i)
        {
            throw new Exception(
                "Internal Parser Error:  Ungrammatical addition of named int arg to top level so occured."
            );
        }

        public void AddArg(string name, string str)
        {
            throw new Exception(
                "Internal Parser Error:  Ungrammatical addition of named string arg to top level so occured."
            );
        }

        public void AddArg(string name, INode node)
        {
            throw new Exception(
                "Internal Parser Error:  Ungrammatical addition of named so arg to top level so occured."
            );
        }

        public void AddArg(int i)
        {
            throw new Exception(
                "Internal Parser Error:  Ungrammatical addition of int arg to top level so occured."
            );
        }

        public void AddArg(string str)
        {
            throw new Exception(
                "Internal Parser Error:  Ungrammatical addition of string arg to top level so occured."
            );
        }

        public void AddArg(INode node)
        {
            if (child == null)
                child = node;
            else
                throw new Exception(
                    "Internal Parser Error:  Ungrammatical addition of second child so to top level so occured."
                );
        }
        #endregion
    }
}
